<?php
Class Controller_Deliverytask extends Controller
{
	public function action_delete_double()
	{
		$log_ids='';
		$base_time=date('Y-m-d H:i:s',strtotime('-1 day'));
		if(isset($_GET['time']) and $_GET['time']){
			$base_time = date('Y-m-d H:i:s',strtotime($_GET['time']));
		}
		$sql="SELECT COUNT( id ) AS num,  `id` ,`orders_products_id`
			FROM  `deliveryorders` 
			WHERE  `type` =10 and `op_time`>'".mysql_escape_string($base_time)."'
			GROUP BY  `orders_products_id` 
			HAVING num >1";
		$flag=true;
	  	do{
			$ids=DB::query(Database::SELECT,$sql)->execute('newerp')->as_array();			
			if($ids and isset($ids[0]['id']) and isset($ids[0]['orders_products_id'])){
				$flag=true;
				
				$pdids = Arr::pluck($ids,'orders_products_id');
				$log_ids .= Arr::unpack_string($pdids,FALSE,',');
				
				$db_ids = Arr::pluck($ids,'id');				
				$sql_string = Arr::unpack_string($db_ids,FALSE,',');
				//$log_ids.=$sql_string;
				$sql_string = " delete from deliveryorders where id in (".$sql_string.")";
				DB::query(Database::DELETE,$sql_string)->execute('newerp');
			}
			else {
				$flag=false;
			}
	  	}while($flag);
	  	
	  	$log_ids = "#".date('Y-m-d H:i:s')."#重复的销售出库ID信息:".$log_ids."#";
	  	echo $log_ids;
	 Log::instance()->add(log::INFO,$log_ids);
	}
}
